package _1域对象;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/test2")
public class TestServlet2 extends HttpServlet {
    int count2=0;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int count1=0;
        count1++;
        System.out.println("test1 count1 "+count1);

        resp.getWriter().println(count1);

        count2++;
        System.out.println("test1 count2 "+count1);

        resp.getWriter().println(count2);

        ServletContext context=this.getServletContext();



        //取信息
        Integer allCount=(Integer)context.getAttribute("allCount");

        if (allCount == null) {
            allCount=0;
        }
        allCount++;//存信息
        context.setAttribute("allCount",allCount);
        context.setAttribute("allCount",allCount);
        resp.getWriter().println("allCount"+allCount);

    }
}
